﻿#include "const.h"
#include "dlgQuery.h"

#define PGID 4001

BEGIN_EVENT_TABLE(dlgQuery, wxDialog)
	EVT_BUTTON( wxID_OK, dlgQuery::OnOK )
	//EVT_PG_CHANGED( PGID, dlgQuery::OnPropertyGridChange )
	END_EVENT_TABLE()

	dlgQuery::dlgQuery(wxWindow*pa,wxString*para)
{
	tmpPara=para;

	wxXmlResource::Get()->LoadDialog(this, pa, wxT("dlgQuery"));

	//
	wxPanel *base=XRCCTRL(*this, "panelSMstart", wxPanel);
	wxBoxSizer*sz=(wxBoxSizer*)base->GetSizer();
	pg=new wxPropertyGrid(base, PGID, wxDefaultPosition, wxDefaultSize, wxPG_BOLD_MODIFIED|wxPG_DEFAULT_STYLE|wxPG_SPLITTER_AUTO_CENTER);
	sz->Add(pg, 1, wxALL|wxEXPAND, 5 );
	//
	//pg->Append( new wxPropertyCategory(wxT("参数设置")) );
	wxPGProperty*mainpg = pg->Append( new wxStringProperty(wxT("参数"),wxPG_LABEL,wxT("<composed>")) );
	
	wxPGProperty*pid =pg->AppendIn( mainpg,new wxStringProperty(wxT("步进电机参数"),wxPG_LABEL,wxT("<composed>")) );

	pg->AppendIn( pid, new wxIntProperty( wxT("取样次数"), wxPG_LABEL,100 ));

	pg->AppendIn( pid, new wxIntProperty( wxT("取样间隔/步"), wxPG_LABEL,1 ) );
	pg->AppendIn( pid, new wxBoolProperty( wxT("正向行走"), wxPG_LABEL, true ) );
	wxArrayString tchoices;
	tchoices.Add(wxT("7"));
	tchoices.Add(wxT("6"));
	tchoices.Add(wxT("5"));
	tchoices.Add(wxT("4"));
	tchoices.Add(wxT("3"));
	tchoices.Add(wxT("2"));
	tchoices.Add(wxT("1"));
	tchoices.Add(wxT("0"));

	pg->AppendIn( pid, new wxEnumProperty(wxT("细分选择"),wxPG_LABEL, tchoices ) );
	//机轴选择
	tchoices.Clear();
	tchoices.Add(wxT("X"));
	tchoices.Add(wxT("Y"));
	pg->AppendIn( pid, new wxEnumProperty(wxT("电机选择"),wxPG_LABEL, tchoices ) );
	//
	pid = pg->AppendIn( mainpg,new wxStringProperty(wxT("读取仪器设置"),wxPG_LABEL,wxT("<composed>")) );
	wxArrayString tchoices2;
	tchoices2.Add(wxT("1"));
	tchoices2.Add(wxT("2"));
	tchoices2.Add(wxT("1,2"));
	pg->AppendIn( pid,new wxEnumProperty(wxT("读取通道选择"),wxPG_LABEL, tchoices2 ) );
	//
	pid = pg->AppendIn( mainpg,new wxStringProperty(wxT("其他功能"),wxPG_LABEL,wxT("<composed>")) );
	
	wxArrayString tchoices3;
	tchoices3.Add(wxT("不返回"));
	tchoices3.Add(wxT("返回起始位置"));
	tchoices3.Add(wxT("返回最高峰(寻峰)"));
	pg->AppendIn( pid,new wxEnumProperty(wxT("返回功能"),wxPG_LABEL, tchoices3 ) );

	pg->AppendIn(  pid,new wxIntProperty(wxT("平均次数"),*(wxString*)0,1 ));

	if(*tmpPara!=wxT(""))
		pg->SetPropertyValue(mainpg,*tmpPara);
}


dlgQuery::~dlgQuery(void)
{
}




void dlgQuery::OnOK(wxCommandEvent&WXUNUSED(e))
{
	/*wxMessageBox(pg->GetPropertyByLabel(wxT("参数"))->GetValueAsString());
	wxMessageBox(pg->GetPropertyByLabel(wxT("参数"))->GetValueAsString(wxPG_COMPOSITE_FRAGMENT));
	*/
	*tmpPara=pg->GetPropertyByLabel(wxT("参数"))->GetValueAsString(wxPG_COMPOSITE_FRAGMENT);


	this->EndModal(wxID_OK);
}
//void dlgQuery::OnPropertyGridChange(wxPropertyGridEvent&e)
//{
//	if(e.GetPropertyName()==wxT(""))
//	{
//		if()
//
//	}
//}





BEGIN_EVENT_TABLE(dlgSelComm, wxDialog)
	EVT_BUTTON( wxID_OK, dlgSelComm::OnOK )
	//EVT_PG_CHANGED( PGID, dlgSelComm::OnPropertyGridChange )
	END_EVENT_TABLE()

	dlgSelComm::dlgSelComm(wxWindow*pa,int* comMotor,int *comReader)
{
	im=comMotor;//0 base
	ir=comReader;
	wxXmlResource::Get()->LoadDialog(this, pa, wxT("dlgSelComm"));
	motor=XRCCTRL(*this, "choiceMotor", wxChoice);
	reader=XRCCTRL(*this, "choiceReader", wxChoice);
	motor->SetSelection(*im);
	reader->SetSelection(*ir);
}


dlgSelComm::~dlgSelComm(void)
{
}




void dlgSelComm::OnOK(wxCommandEvent&WXUNUSED(e))
{
	*im=motor->GetSelection();
	*ir=reader->GetSelection();


	this->EndModal(wxID_OK);
}
